﻿	var map=null;

	function getparastr(strname)
  {
   var hrefstr,pos,parastr,para,tempstr;
   hrefstr = window.location.href;
   pos = hrefstr.indexOf("?")
   parastr = hrefstr.substring(pos+1);
   para = parastr.split("&");
   tempstr="";
   for(i=0;i<para.length;i++)
   {
    tempstr = para[i];
    pos = tempstr.indexOf("=");
    if(tempstr.substring(0,pos) == strname)
    {
     return tempstr.substring(pos+1);
     }
   }
   return "";
  }	
    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(38, 109),4);
        map.addMapType(G_PHYSICAL_MAP);
	    map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
		map.removeMapType(G_SATELLITE_MAP); 
        map.setMapType(G_PHYSICAL_MAP);
		getkml();
      }
    }

	function LabelSp(spdist) {
	  var photos=spdist.split('#'); 
      var marker = new GMarker(new GLatLng(photos[2],photos[3]));
      var html ='县名：'+photos[0]+'，数量：'+photos[1];
      map.openInfoWindowHtml(new GLatLng(photos[2],photos[3]),html);
	  GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
 function getkml(){ 
 var kmlidx=getparastr('lsid');
  $.ajax({type: "GET", url: "include/dist.php",data: "lsid="+kmlidx,     
    success: function(msg){
    map.clearOverlays(); 
	 var temp=msg.split('%'); //返回的字符串分隔符是 %
	 for(var i=0;i<temp.length-1;i++)  {	
	   map.addOverlay(LabelSp(temp[i]));
	}
	}   
  }); 
} 